﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BaccaratRally.DataKernel.Entity
{
    [BaccaratRally.DataKernel.Entity.SqlTableAttribute("User")]
    public class User : BaccaratRally.DataKernel.Entity.EntityBase
    {

        #region data fields
        [BaccaratRally.DataKernel.Entity.SqlFieldAttribute("UserName", true, true, false, false)]
        public System.String UserName { get; set; }

        [BaccaratRally.DataKernel.Entity.SqlFieldAttribute("Password", false, false, false, false)]
        public System.String Password { get; set; }

        [BaccaratRally.DataKernel.Entity.SqlFieldAttribute("LastActive", false, false, false, false)]
        public System.DateTime LastActive { get; set; }

        [BaccaratRally.DataKernel.Entity.SqlFieldAttribute("SystemStatus", false, false, false, false)]
        public System.Byte SystemStatus { get; set; }

        [BaccaratRally.DataKernel.Entity.SqlFieldAttribute("UserSetting", false, false, true, false)]
        public System.String UserSetting { get; set; }

        #endregion

        internal override void ReBuildInstance(System.Data.SqlClient.SqlDataReader reader)
        {
            this.UserName = GetReaderValue<System.String>(reader, "UserName");
            this.Password = GetReaderValue<System.String>(reader, "Password");
            this.LastActive = GetReaderValue<System.DateTime>(reader, "LastActive");
            this.SystemStatus = GetReaderValue<System.Byte>(reader, "SystemStatus");
            this.UserSetting = GetReaderValue<System.String>(reader, "UserSetting");
        }

        internal override System.Data.SqlClient.SqlParameter[] BuildInsertParamter()
        {
            BaccaratRally.DataKernel.SqlGateway.DbSqlParamterCollection paramterList = new BaccaratRally.DataKernel.SqlGateway.DbSqlParamterCollection();
            paramterList.Add(new System.Data.SqlClient.SqlParameter("@UserName", System.Data.SqlDbType.VarChar, 20));
            paramterList["@UserName"].Value = this.UserName;
            paramterList.Add(new System.Data.SqlClient.SqlParameter("@Password", System.Data.SqlDbType.VarChar, 50));
            paramterList["@Password"].Value = this.Password;
            paramterList.Add(new System.Data.SqlClient.SqlParameter("@LastActive", System.Data.SqlDbType.DateTime, 8));
            paramterList["@LastActive"].Value = this.LastActive;
            paramterList.Add(new System.Data.SqlClient.SqlParameter("@SystemStatus", System.Data.SqlDbType.TinyInt, 1));
            paramterList["@SystemStatus"].Value = this.SystemStatus;
            paramterList.Add(new System.Data.SqlClient.SqlParameter("@UserSetting", System.Data.SqlDbType.VarChar, 200));
            paramterList["@UserSetting"].Value = this.UserSetting;
            return paramterList.ToArray();
        }

        internal override System.Data.SqlClient.SqlParameter[] BuildUpdateParamter()
        {
            BaccaratRally.DataKernel.SqlGateway.DbSqlParamterCollection paramterList = new BaccaratRally.DataKernel.SqlGateway.DbSqlParamterCollection();
            return paramterList.ToArray();
        }

        internal override string GetInsertCommandText()
        {
            string sqlcmd = @"insert dbo.[User]([UserName],[Password],[LastActive],[SystemStatus],[UserSetting])
                          values(@UserName, @Password, @LastActive, @SystemStatus, @UserSetting)
                          select * from dbo.[User] where 1=1
                        ";
            return sqlcmd;
        }

        internal override string GetUpdateCommandText()
        {
            string sqlcmd = @"";
            return sqlcmd;
        }
    }

}
